package com.dcjt.firehotcarpad.moudle

import android.annotation.SuppressLint
import android.app.AlertDialog
import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.view.View
import com.aries.library.fast.manager.RxJavaManager
import com.aries.library.fast.util.FastUtil
import com.aries.library.fast.util.SPUtil
import com.aries.ui.view.title.TitleBarView
import com.aries.ui.widget.progress.UIProgressView
import com.dcjt.firehotcarpad.R
import com.dcjt.firehotcarpad.base.SPConstant
import com.dcjt.firehotcarpad.utils.LoginUtil
import com.juntu.loginlib.ui.BaseSplashActivity
import kotlinx.android.synthetic.main.activity_splash.*
import kotlin.system.exitProcess

/*
1.   //请求基础数据   pmq,pmqEnum,ZNZH_KZ_Cmd
2.   //获取消息应用信息
3.   //注册应用信息（没有 就注册）
 */
class SplashActivity : BaseSplashActivity() {

    private var dialog: UIProgressView? = null

    override fun getLayoutId(): Int = R.layout.activity_splash

    @SuppressLint("SetTextI18n")
    override fun initView(savedInstanceState: Bundle?) {
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
        tv_versionSplash.text = "V${FastUtil.getVersionName(this)}"
        findViewById<TitleBarView>(R.id.titleBar_headFastLib).visibility = View.GONE
        dialog = UIProgressView(this@SplashActivity, UIProgressView.STYLE_WEI_BO).setMessage("初始化中...")
        dialog?.setCancelable(false)
    }

    override fun startMainActivity() {
        startActivity(Intent(this, NewMainActivity::class.java))
        finish()
    }

    override fun getSystemConfigType(): String =
        "appServerUrl,loginPlace,jcj_pmqEnum.JCJ_Cmd,znzh_pmqEnum.ZNZH_TB_Cmd"

    override fun startLoginActivity() {
        dialog?.show()
        RxJavaManager.getInstance().setTimer(
            500
        )
        {
            startActivity(Intent(this, LoginActivity::class.java))
            finish()
        }
    }

    override fun saveLoginInfo(loginResult: String?) = LoginUtil.parseLoginResult(loginResult)

    override fun parseConfig(config: String?) = LoginUtil.parseConfigData(config)

    override fun showDialog(msg: String?) {
        if(dialog != null){
            dialog?.show();
        }
    }

    override fun dismissDialog() {
        if (dialog != null ) {
            dialog?.dismiss()
            dialog = null
        }

    }

    override fun showErrorTips(msg: String?) {
        AlertDialog.Builder(this)
            .setTitle("提醒")
            .setMessage(msg)
            .setPositiveButton(
                "确定"
            ) { dialog, _ ->
                exitProcess(0)
                dialog.dismiss()
            }
            .create().show()
    }

}
